<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>工作日计算器</title>
    <link rel="stylesheet" href="https://www.unpkg.com/ew-message/dist/ew-message.min.css">
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f7fc;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .container {
            background-color: #ffffff;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            padding: 20px;
            width: 100%;
            max-width: 400px;
        }

        h1 {
            font-size: 24px;
            color: #333;
            text-align: center;
            margin-bottom: 20px;
        }

        .input-group {
            margin-bottom: 15px;
        }

        .input-group label {
            display: block;
            font-size: 14px;
            color: #666;
            margin-bottom: 5px;
        }

        .input-group input {
            width: 100%;
            padding: 10px;
            font-size: 16px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }

        .button {
            background-color: #4CAF50;
            color: white;
            padding: 12px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
            font-size: 16px;
            transition: background-color 0.3s;
        }

        .button:hover {
            background-color: #45a049;
        }

        .result {
            margin-top: 20px;
            font-size: 18px;
            text-align: center;
            color: #333;
            font-weight: bold;
        }
    </style>
</head>

<body>

    <div class="container">
        <h1>工作日计算器</h1>

        <div class="input-group">
            <label for="startDate">选择起始日期</label>
            <input type="date" id="startDate" />
        </div>

        <div class="input-group">
            <label for="businessDays">增加的工作日数</label>
            <input type="number" id="businessDays" min="1" />
        </div>

        <button class="button" onclick="calculateBusinessDay()">计算</button>

        <div class="result" id="result"></div>
    </div>

    <script src="https://www.unpkg.com/ew-message/dist/ew-message.min.js"></script>
    <script>
        const addBusinessDay = (startDate, n) =>
            Array.from({ length: n }).reduce(date => {
                date = new Date(date.setDate(date.getDate() + 1));
                // 判断如果是非工作日，即周六周日
                if (date.getDay() === 6) // 周六
                    date = new Date(date.setDate(date.getDate() + 2)); // 跳到下周一
                if (date.getDay() === 0) // 周日
                    date = new Date(date.setDate(date.getDate() + 1)); // 跳到下周一
                return date;
            }, startDate);

        function calculateBusinessDay() {
            const startDate = document.getElementById("startDate").value;
            const businessDays = parseInt(document.getElementById("businessDays").value);

            if (!startDate || isNaN(businessDays) || businessDays <= 0) {
                ewMessage("请输入有效的日期和工作日数");
                return;
            }

            const start = new Date(startDate);
            const resultDate = addBusinessDay(start, businessDays);

            // 格式化结果日期为YYYY-MM-DD
            const resultStr = resultDate.toISOString().split('T')[0];

            document.getElementById("result").textContent = `计算结果：${resultStr}`;
        }
    </script>

</body>

</html>